package com.fanqwz.kotlinmvvm.ui.activity.main

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.fanqwz.kotlinmvvm.R
import com.fanqwz.kotlinmvvm.ui.activity.BaseActivity
import com.fanqwz.kotlinmvvm.ui.compositor.ViewCompositor
import com.fanqwz.kotlinmvvm.ui.fragment.main.MainFragment


class MainActivity : BaseActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Example of a call to a native method
//        val tv = findViewById(R.id.sample_text) as TextView
//        tv.text = stringFromJNI()

//        setContentView(R.layout.activity_main)
//        supportFragmentManager.beginTransaction()
//                .replace(R.id.fragment, MainFragment())
//                .commit()

//        CheckPermission.instance(this).check(PermissionItem(Manifest.permission.READ_EXTERNAL_STORAGE,
//                Manifest.permission.WRITE_EXTERNAL_STORAGE), object : PermissionListener {
//            override fun permissionGranted() {
//                //获取到权限时执行正常业务逻辑
//                logger.debug("CheckPermission: granted")
//            }
//
//            override fun permissionDenied() {
//                //权限被拒绝时给用户友好提示
//                logger.error("CheckPermission: denied")
//            }
//        })
    }

    override fun onViewHierarchyBuilt() {
        supportFragmentManager.beginTransaction()
                .replace(R.id.fragment, MainFragment())
                .commit()
    }

    override fun buildViewCompositor(): ViewCompositor {
        return object : ViewCompositor() {
            override fun inflateView(layoutInflater: LayoutInflater): View? {
                return layoutInflater.inflate(R.layout.activity_main, null)
            }

        }.apply {
            super.buildViewCompositor().addChild(this)
        }
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    external fun stringFromJNI(): String

    companion object {

        // Used to load the 'native-lib' library on application startup.
        init {
//            System.loadLibrary("native-lib")
        }
    }
}
